<template>
  <div class="contract-list">
    <el-table :data="list" style="width: 100%" :show-header="false">
      <el-table-column label="Title" min-width="200">
        <template slot-scope="{ row }">
          <el-button type="text" @click="onShowDetail(row)">{{ row.title }}</el-button>
        </template>
      </el-table-column>
      <el-table-column label="Status" width="100" align="center">
        <template slot-scope="{ row }">
          <el-tag :type="row.statusType">
            {{ row.status }}
          </el-tag>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { FLOW_STATUS_TEXT } from '@common/consts/status';

const FLOW_STATUS_TYPE = {
  PART: 'warning',
  ALL: 'success',
  REJECT: 'danger',
  CANCEL: 'danger',
  WILLEXPIRE: 'danger',
  DEADLINE: 'danger',
  EXCEPTION: 'danger',
  STOPPED: 'danger',
};

export default {
  props: {
    contractList: {
      type: Array,
      default: () => [],
    },
  },
  methods: {
    onShowDetail(row) {
      this.$router.push(`/contract/detail/${row.flowId}`);
    },
  },
  computed: {
    list() {
      const r = this.contractList.map(contract => ({
        flowId: contract.FlowId,
        title: contract.FlowName,
        status: FLOW_STATUS_TEXT[contract.FlowStatus],
        statusType: FLOW_STATUS_TYPE[contract.FlowStatus],
      }));
      return r;
    },
  },
};
</script>

<style lang="scss" scoped>
ul,
li {
  margin: 0;
  padding: 0;
  list-style: none;
}
</style>
